package com.yq.socket1.day1.v1;

import com.sun.javafx.image.impl.ByteRgb;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author 3307235355@qq.com
 * @description
 * @since 2022/07/01 09:36
 */
public class Server {
    public static void main(String[] args) throws IOException {
        //    创建客户端的Server socket
        ServerSocket serverSocket = new ServerSocket(8888);
        //    accept方法建立连接，得到socket
        Socket socket = serverSocket.accept();
        //    获取输入输出流
        InputStream in = socket.getInputStream();
        //    利用输入输出流进行读写操作
        byte[] bytes = new byte[1024];
        int read = in.read(bytes);
        System.out.println(new String(bytes,0,read));
        System.out.println(socket.getInetAddress());
        //    close
        in.close();
    }
}
